﻿ function ReplaceCarac(val, de, para) {
    val = val.replace(de, para);
    if (val.indexOf(de) > -1)
        return ReplaceCarac(val, de, para);
    else
        return val;
}
function IsNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var possuiNum = false;
    var Char;

    for (var i = 0; i < sText.length && IsNumber == true; i++) {
        possuiNum = true;
        Char = sText.charAt(i);z
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}


//<!-- Begin

var version4 = (navigator.appVersion.charAt(0) == "4");
var popupHandle;

function trocaImg(controle, i) {
	document.getElementById(controle).src = i;
}

function modalWin(url, name, width, height) {

    var properties = "";

    if (!document.all) {
        var leftPos = (screen.width / 2) - (width / 2);
        var topPos = (screen.height / 2) - (height / 2);
        properties = "dialogTop:" + topPos + "; dialogLeft: " + leftPos + "; dialogWidth:" + width + "px;dialogHeight:" + height + "px";
    }
    else {
        properties = "dialogWidth:" + width + "px;dialogHeight:" + height + "px";
    }
    
    if (window.showModalDialog) {
        window.showModalDialog(url, name, properties);
    }
}

function openPopup(position, url, name, evnt, width, height) {

	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
	var properties = "scrollbars=yes, toolbar = 0, location = 0, height = " + height + ", width=" + width;

	if (navigator.appName == "Microsoft Internet Explorer") {
		screenY = document.body.offsetHeight;
		screenX = window.screen.availWidth;
	}
	else {
	    screenY = window.outerHeight;
	    screenX = window.outerWidth;
	}

	if (position == 1) {
		cursorX = evnt.screenX;
		cursorY = evnt.screenY;
		padAmtX = 10;
		padAmtY = 10;
		if ((cursorY + height + padAmtY) > screenY) {
			// make sizes a negative number to move left/up
			padAmtY = (-30) + (height * -1);
			// if up or to left, make 30 as padding amount
		}
		if ((cursorX + width + padAmtX) > screenX) {
			padAmtX = (-30) + (width * -1);
			// if up or to left, make 30 as padding amount
		}
		if (navigator.appName == "Microsoft Internet Explorer") {
			leftprop = cursorX + padAmtX;
			topprop = cursorY + padAmtY;
		}
		else {
			leftprop = (cursorX - pageXOffset + padAmtX);
			topprop = (cursorY - pageYOffset + padAmtY);
		}
	}
	else {
		leftvar = (screenX - width) / 2;
		rightvar = (screenY - height) / 2;
		if (navigator.appName == "Microsoft Internet Explorer") {
			leftprop = leftvar;
			topprop = rightvar;
		}
		else {
			leftprop = (leftvar - pageXOffset);
			topprop = (rightvar - pageYOffset);
		}
	}
	if (evnt != null) {
		properties = properties + ", left = " + leftprop;
		properties = properties + ", top = " + topprop;
	}

	closePopup();

    popupHandle = open(url, name, properties);
}

function closePopup() {
	if (popupHandle != null && !popupHandle.closed) popupHandle.close();
}

function displayPopup(position, url, name, evnt) {

	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt, height = 400, width = 794;
	var properties = "scrollbars=yes, toolbar = 0, location = 0, height = " + height + ", width=" + width;

	if (navigator.appName == "Microsoft Internet Explorer") {
		screenY = document.body.offsetHeight;
		screenX = window.screen.availWidth;
	}
	else {
	    screenY = window.outerHeight;
	    screenX = window.outerWidth;
	}

	if (position == 1) {
		cursorX = evnt.screenX;
		cursorY = evnt.screenY;
		padAmtX = 10;
		padAmtY = 10;
		if ((cursorY + height + padAmtY) > screenY) {
			// make sizes a negative number to move left/up
			padAmtY = (-30) + (height * -1);
			// if up or to left, make 30 as padding amount
		}
		if ((cursorX + width + padAmtX) > screenX) {
			padAmtX = (-30) + (width * -1);
			// if up or to left, make 30 as padding amount
		}
		if (navigator.appName == "Microsoft Internet Explorer") {
			leftprop = cursorX + padAmtX;
			topprop = cursorY + padAmtY;
		}
		else {
			leftprop = (cursorX - pageXOffset + padAmtX);
			topprop = (cursorY - pageYOffset + padAmtY);
		}
	}
	else {
		leftvar = (screenX - width) / 2;
		rightvar = (screenY - height) / 2;
		if (navigator.appName == "Microsoft Internet Explorer") {
			leftprop = leftvar;
			topprop = rightvar;
		}
		else {
			leftprop = (leftvar - pageXOffset);
			topprop = (rightvar - pageYOffset);
		}
	}
	if (evnt != null) {
		properties = properties + ", left = " + leftprop;
		properties = properties + ", top = " + topprop;
	}

	closePopup();
	popupHandle = open(url, name, properties);
}


function ValidaPeriodo(src, args) {
    var data1 = document.getElementById('<%= txtPeriodoSolicitao.ClientID%>').value;
    var data2 = document.getElementById('<%= txtPeriodoSolicitaoAte.ClientID%>').value;

    if (data1 != "" && data2 != "") {
        var d1 = new Date(data1.substr(6, 4), data1.substr(3, 2) - 1, data1.substr(0, 2));
        var d2 = new Date(data2.substr(6, 4), data2.substr(3, 2) - 1, data2.substr(0, 2));

        if (d1 >= d2) {
            args.IsValid = false;
        }
        else {
            args.IsValid = true;
        }
    }
    else if ((data1 != "" && data2 == "") || (data1 == "" && data2 != "")) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}



//	End -->